package com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;

import com.tjsinfo.tjsoa.Dao.ISpringDao;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.FaWenInfo;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.MainType;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.SubTypeInfo;

public class FaWenAdminBO  implements IFaWenAdminBO{
	private ISpringDao springDao;
	
	public ISpringDao getSpringDao() {
		return springDao;
	}

	public void setSpringDao(ISpringDao springDao) {
		this.springDao = springDao;
	}

	/**
	 *  所有待办文件
	 * @param actiorid
	 * @return
	 */
	public List<FaWenInfo> selectFaWenAll(Integer actiorid){
		List<FaWenInfo> faWenInfoList = new ArrayList<FaWenInfo>();
		
		String sql = "EXEC [dbo].[selectfawentask] @actorid = ?";
		faWenInfoList =  springDao.querySQL(sql, new Object[]{actiorid}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				FaWenInfo faWenInfo = new FaWenInfo();
				faWenInfo.setBiaoti(arg0.getString("biaoti"));
				if (arg0.getString("wenhaotype") == null ) {
					faWenInfo.setWenhaotype("");
				}else{
					faWenInfo.setWenhaotype(arg0.getString("wenhaotype"));
				}
				faWenInfo.setId(arg0.getString("id"));
				faWenInfo.setTaskId(arg0.getInt("taskId"));
				faWenInfo.setTableName(arg0.getString("tablename"));
				faWenInfo.setState(arg0.getInt("state"));
				faWenInfo.setNodename(arg0.getString("nodename"));
				faWenInfo.setZhuangta(arg0.getString("zhuangta"));
				return faWenInfo;
			}
			
		});
		return faWenInfoList;
	}

	/**
	 *  办理中文件
	 * @param actiorid
	 * @return
	 */
	public List<FaWenInfo> selectFaWenByBanLiZhong(Integer actiorid){
		List<FaWenInfo> faWenInfoList = new ArrayList<FaWenInfo>();
		
		String sql = "EXEC [dbo].[selectbanlizhong] @userid = ?,@taskuserid = ?";
		faWenInfoList =  springDao.querySQL(sql, new Object[]{"%,"+actiorid+",%",actiorid}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				FaWenInfo faWenInfo = new FaWenInfo();
				faWenInfo.setBiaoti(arg0.getString("biaoti"));
				if (arg0.getString("wenhaotype") == null ) {
					faWenInfo.setWenhaotype("");
				}else{
					faWenInfo.setWenhaotype(arg0.getString("wenhaotype"));
				}
				if (arg0.getString("username") == null || "".equals(arg0.getString("username"))) {
					faWenInfo.setPeople("");
				}else{
					faWenInfo.setPeople("（"+ arg0.getString("username") + "）");
				}
				if("拟稿人修改内容".equals((arg0.getString("NAME_")))){
					faWenInfo.setWeizhi("拟稿人修改");
				}else{
					faWenInfo.setWeizhi(arg0.getString("NAME_"));
				}
				faWenInfo.setWeizhi(arg0.getString("NAME_"));
				faWenInfo.setId(arg0.getString("id"));
				faWenInfo.setTableName(arg0.getString("tablename"));
				faWenInfo.setState(arg0.getInt("state"));
				faWenInfo.setFlowId(arg0.getInt("flowid"));
				return faWenInfo;
			}
			
		});
		return faWenInfoList;
	}

	/**
	 * 查找当前用户拟稿的办理中文件
	 * @param actiorid 当前用户id
	 * @return
	 */
	public List<FaWenInfo> selectFaWenNigaoren(Integer actioridint) {
		List<FaWenInfo> faWenInfoList = new ArrayList<FaWenInfo>();
		
		String sql = "EXEC [dbo].[selectnigaobanlizhong] @userid = ?";
		faWenInfoList =  springDao.querySQL(sql, new Object[]{actioridint}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				FaWenInfo faWenInfo = new FaWenInfo();
				faWenInfo.setBiaoti(arg0.getString("biaoti"));
				if (arg0.getString("wenhaotype") == null ) {
					faWenInfo.setWenhaotype("");
				}else{
					faWenInfo.setWenhaotype(arg0.getString("wenhaotype"));
				}
				if (arg0.getString("username") == null || "".equals(arg0.getString("username"))) {
					faWenInfo.setPeople("");
				}else{
					faWenInfo.setPeople("（"+ arg0.getString("username") + "）");
				}
				faWenInfo.setWeizhi(arg0.getString("NAME_"));
				faWenInfo.setId(arg0.getString("id"));
				faWenInfo.setTableName(arg0.getString("tablename"));
				faWenInfo.setState(arg0.getInt("state"));
				return faWenInfo;
			}
			
		});
		return faWenInfoList;
	}

}
